<!DOCTYPE html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="contextPath" value="${pageContext.request.contextPath}" />
<%
int userType = (Integer)session.getAttribute("usertype");
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>查看标注说明页</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta content="width=device-width, initial-scale=1" name="viewport">
<link rel="stylesheet" type="text/css" href="${contextPath}/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="${contextPath}/css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css" href="${contextPath}/css/umeditor.min.css" />
<link rel="stylesheet" type="text/css" href="${contextPath}/css/public.css">
<script type="text/javascript" src="${contextPath}/js/jquery.min.js"></script>
<script type="text/javascript" src="${contextPath}/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${contextPath}/js/umeditor.config.js"></script>
<script type="text/javascript" src="${contextPath}/js/umeditor.js"></script>
<script type="text/javascript" src="${contextPath}/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="${contextPath}/js/common.js"></script>
</head>
<body>
	
	<div class="container">
		<div class="panel panel-default">
			<div class="panel-heading">
				<% 
					if(userType == 1){
						%>
							<span>文章状态: </span>
							<span class="label label-primary">
								<c:choose>
								    <c:when test="${article.isTop==1 }">
								 		置顶
								    </c:when>
								    <c:otherwise>
								       	未置顶
								    </c:otherwise>
								</c:choose>
							</span>&nbsp;&nbsp;
							<span class="label label-warning">
								<c:choose>
								    <c:when test="${article.isLocked==1 }">
								 		禁止评论
								    </c:when>
								    <c:otherwise>
								       	开启评论
								    </c:otherwise>
								</c:choose>
							</span>
						<%
					}
				%>
			</div>
			<div class="panel-body">
				<div id="contentArea" style="margin-left: 20px;margin-right: 20px;">
					<form role="form" class="form-horizontal">
						<div class="form-group" id="">
							<label for="noteTitle" class="col-sm-2 control-label">文章标题：</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" value='${article.articleTitle}' name="noteTitle" id="noteTitle" placeholder="规则名称" required="required" autocomplete="off">
								<span class="help-block"></span>
							</div>
						</div>
						<script type="text/plain" id="myEditor" style="width:100%;height:240px;">${article.articleContent}</script>
						<div style="text-align: center; margin-top: 10px;">
							<% 
								if(userType == 1){
									%>
										<c:choose>
											<c:when test="${article.isTop==1 }">
												<button type="button" id="topArticle" class="btn btn-primary">取消置顶</button>&nbsp;&nbsp;&nbsp;&nbsp;
											</c:when>
											<c:otherwise>
										      	<button type="button" id="topArticle" class="btn btn-primary">文章置顶</button>&nbsp;&nbsp;&nbsp;&nbsp;
										    </c:otherwise>
										</c:choose>
										<c:choose>
											<c:when test="${article.isLocked==1 }">
												<button type="button" id="lockArticle" class="btn btn-warning">开启评论</button>&nbsp;&nbsp;&nbsp;&nbsp;
											</c:when>
											<c:otherwise>
										      	<button type="button" id="lockArticle" class="btn btn-warning">禁止评论</button>&nbsp;&nbsp;&nbsp;&nbsp;
										    </c:otherwise>
										</c:choose>
									<%
								}
							%>
							<button type="button" id="saveEdit" class="btn btn-success">更新文章</button>
						</div>
					</form>
				</div>
			</div>
		</div>
		<div style="text-align: center;">
			
		</div>
		<input type="hidden" id="articleId" value="${article.id}">
	</div>
	<script type="text/javascript">
		
		window.UMEDITOR_CONFIG.imageUrl = "${contextPath}/security/uploadArticleImage";
		window.UMEDITOR_CONFIG.initialFrameHeight = "500";
		var um = UM.getEditor('myEditor');
		$("#saveEdit").click(function(){
			var hasContent = false;
			hasContent = UM.getEditor('myEditor').hasContents();
			if(hasContent){
				var articleId = $("#articleId").val();
				var con = UM.getEditor('myEditor').getContent();
				var noteTitle = $("#noteTitle");
				if(checkout.text.isempty(noteTitle,"名称不能为空！"))return;
				$.ajax({
					type:'POST',
					url:'${contextPath}/security/editArticle',
					data:{"title":noteTitle.val(),"content":con,"id":articleId},
					dataType:'json',
					success:function(data){
						if(data.replay == "1"){
							alert(data.message);
						}else{
							alert(data.message);
						}
					}
				});
			}
		});
		
		<% 
			if(userType == 1){
				%>
					var isTop = ${article.isTop};
					var islocked = ${article.isLocked};
					$("#topArticle").click(function(){
						var articleId = $("#articleId").val();
						var confirmStr;
						var changeStatus;
						if(isTop==0){
							confirmStr = "确定要置顶该文章吗？";
							changeStatus = 1;
						}else{
							confirmStr = "确定要取消文章置顶吗？";
							changeStatus = 0;
						}
						var conWin = confirm(confirmStr);
						if (conWin) {
							$.ajax({
								type: 'POST',
								url: '${contextPath}/security/changeTopStatus',
								data: {"id": articleId, "isTop":changeStatus},
								dataType: 'json',
								success: function (data) {
									alert(data.message);
									window.location.reload();
								}
							});
						}
					});
					
					$("#lockArticle").click(function(){
						var articleId = $("#articleId").val();
						var confirmStr;
						var changeStatus;
						if(islocked==0){
							confirmStr = "确定要禁止文章评论吗？";
							changeStatus = 1;
						}else{
							confirmStr = "确定要开启文章评论吗？？";
							changeStatus = 0;
						}
						var conWin = confirm(confirmStr);
						if (conWin) {
							$.ajax({
								type: 'POST',
								url: '${contextPath}/security/changeLockStatus',
								data: {"id": articleId, "isLock":changeStatus},
								dataType: 'json',
								success: function (data) {
									alert(data.message);
									window.location.reload();
								}
							});
						}
					});
				<%
			}
		%>
		
		
		
		
		
	</script>
</body>
</html>
